package mao.exaimnation.tengxun;

import java.util.Scanner;

/**
 * @author Totoro
 * @date 2020/9/6
 * @explain: 两个链表降序排列，找出两个链表的公共子序列
 * 思路：直接哪个大就指针向后移动，
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int n = scanner.nextInt();
            int[] list1 = new int[n];
            for (int i = 0; i < n; i++) {
                list1[i]=scanner.nextInt();
            }
            int m = scanner.nextInt();
            int[] list2 = new int[m];
            for (int i = 0; i < m; i++) {
                list2[i] = scanner.nextInt();
            }

            int index1=0,index2=0;
            while (index1 < n && index2<m){
                if (list1[index1] > list2[index2]){
                    index1++;
                }else if (list1[index1] < list2[index2]){
                    index2++;
                }else {
                    System.out.print(list1[index1]+" ");
                    index1++;
                    index2++;
                }
            }
            System.out.println(); //换行
        }
    }
}
